home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / unzip51 / amiga / stat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-06  |  3.8 KB  |  137 lines

  1. /* stat.c -- for Lattice 4.01 or Aztec 5.2b */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/exec.h>
  5. #include <libraries/dos.h>
  6. #include <libraries/dosextens.h>
  7. #ifdef AZTEC_C
  8. #  include <clib/exec_protos.h>
  9. #  include <clib/dos_protos.h>
  10. #  include <pragmas/exec_lib.h>
  11. #  include <pragmas/dos_lib.h>
  12. #  include "amiga/z-stat.h"        /* fake version of stat.h */
  13. #else
  14. #  include <sys/types.h>
  15. #  include <sys/stat.h>
  16. #  include <proto/exec.h>        /* I think these are only for      */
  17. #  include <proto/dos.h>        /* Lattice versions older than 5.0 */
  18. #endif
  19.  
  20. /* The Aztec stat.h header is completely unsuitable, since it defines only */
  21. /* a very minimal struct stat with no st_mode field.  So we roll our own,  */
  22. /* which needs to be pulled in by unzip.h for everyone who calls stat().   */
  23.  
  24. #ifndef SUCCESS
  25. #define SUCCESS (-1)
  26. #define FAILURE (0)
  27. #endif
  28.  
  29. extern int stat(char *file,struct stat *buf);
  30.  
  31. stat(file,buf)
  32. char *file;
  33. struct stat *buf;
  34. {
  35.  
  36.         struct FileInfoBlock *inf;
  37.         struct FileLock *lock;
  38.         long ftime;
  39.  
  40.         if( (lock = (struct FileLock *)Lock(file,SHARED_LOCK))==0 )
  41.                 /* file not found */
  42.                 return(-1);
  43.  
  44.         if( !(inf = (struct FileInfoBlock *)AllocMem(
  45.                 (long)sizeof(struct FileInfoBlock),MEMF_PUBLIC|MEMF_CLEAR)) )
  46.         {
  47.                 UnLock((BPTR)lock);
  48.                 return(-1);
  49.         }
  50.  
  51.         if( Examine((BPTR)lock,inf)==FAILURE )
  52.         {
  53.                 FreeMem((char *)inf,(long)sizeof(*inf));
  54.                 UnLock((BPTR)lock);
  55.                 return(-1);
  56.         }
  57.  
  58.         /* fill in buf */
  59.  
  60.         buf->st_dev                =
  61.         buf->st_nlink        =
  62.         buf->st_uid                =
  63.         buf->st_gid                =
  64.         buf->st_rdev        = 0;
  65.         
  66.         buf->st_ino                = inf->fib_DiskKey;
  67.         buf->st_blocks        = inf->fib_NumBlocks;
  68.         buf->st_size        = inf->fib_Size;
  69.         buf->st_blksize        = 512;
  70.  
  71.         /* now the date.  AmigaDOG has weird datestamps---
  72.          *      ds_Days is the number of days since 1-1-1978;
  73.          *      however, as Unix wants date since 1-1-1970...
  74.          */
  75.  
  76.         ftime =
  77.                 (inf->fib_Date.ds_Days * 86400 )                +
  78.                 (inf->fib_Date.ds_Minute * 60 )                 +
  79.                 (inf->fib_Date.ds_Tick / TICKS_PER_SECOND )     +
  80.                 (86400 * 8 * 365 )                              +
  81.                 (86400 * 2 );  /* two leap years, I think */
  82.  
  83. /*  ftime += timezone;  */
  84.  
  85.         buf->st_ctime =
  86.         buf->st_atime =
  87.         buf->st_mtime = ftime;
  88.  
  89.     buf->st_mode = (inf->fib_DirEntryType < 0 ? S_IFREG : S_IFDIR);
  90.  
  91.         /* lastly, throw in the protection bits */
  92.  
  93.         if((inf->fib_Protection & FIBF_READ) == 0)
  94.                 buf->st_mode |= S_IREAD;
  95.  
  96.         if((inf->fib_Protection & FIBF_WRITE) == 0)
  97.                 buf->st_mode |= S_IWRITE;
  98.  
  99.         if((inf->fib_Protection & FIBF_EXECUTE) == 0)
  100.                 buf->st_mode |= S_IEXECUTE;
  101.  
  102.         if((inf->fib_Protection & FIBF_DELETE) == 0)
  103.                 buf->st_mode |= S_IDELETE;
  104.  
  105.         if((inf->fib_Protection & (long)FIBF_ARCHIVE))
  106.                 buf->st_mode |= S_IARCHIVE;
  107.  
  108.         if((inf->fib_Protection & (long)FIBF_PURE))
  109.                 buf->st_mode |= S_IPURE;
  110.  
  111.         if((inf->fib_Protection & (long)FIBF_SCRIPT))
  112.                 buf->st_mode |= S_ISCRIPT;
  113.  
  114.         FreeMem((char *)inf, (long)sizeof(*inf));
  115.         UnLock((BPTR)lock);
  116.  
  117.         return(0);
  118.  
  119. }
  120.  
  121.  
  122. #ifdef AZTEC_C
  123.  
  124. /* This here removes unnecessary bulk from the executable with Aztec: */
  125. void _wb_parse()  { }
  126.  
  127. /* This here pretends we have time zone support and suchlike when we don't: */
  128. long timezone = 0;
  129. void tzset()  { }
  130. /* AmigaDOS only has timezone awareness in release 2.1 and newer. */
  131.  
  132. int umask()  { return 0; }
  133. /* I think this has something to do with user access privilege? */
  134.  
  135. #endif
  136.  
  137.